package minisoft.application.loterryservice;

import android.app.Activity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.text.format.Time;
import android.view.View;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

public class TodayActivity extends Activity {
	private ListView mainListView;
	private TextView today;
	private List<Today> myListItems;
	private TodayDataSource todayDatasource;
	private Calendar date_today = Calendar.getInstance();

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_today);

		// Get today date
		today = (TextView) findViewById(R.id.today);
		// TODO Get today date from server
		Time now = new Time();
		now.setToNow();
		today.setText(getResources().getString(R.string.today)
				+ getResources().getStringArray(R.array.day_of_week)[date_today
						.get(Calendar.DAY_OF_WEEK)] + ", "
				+ String.valueOf(date_today.get(Calendar.DAY_OF_MONTH)) + "/"
				+ String.valueOf(date_today.get(Calendar.MONTH)) + "/"
				+ String.valueOf(date_today.get(Calendar.YEAR)));

		todayDatasource = new TodayDataSource();

		myListItems = todayDatasource.searchTodaysByDateInWeek(
				this, date_today.get(Calendar.DAY_OF_WEEK));

		TodayAdapter todayAdapter = new TodayAdapter(this,
				myListItems);

		// Find the ListView resource.
		mainListView = (ListView) findViewById(R.id.mainListView);

		mainListView.setAdapter(todayAdapter);
		/*
		 * // Create and populate a List of province names. String[] provinces =
		 * new String[] { "Ha Noi", "Da Nang", "Hue", "TP HCM", "An Giang"};
		 * ArrayList<String> provinceList = new ArrayList<String>();
		 * provinceList.addAll( Arrays.asList(provinces) );
		 * 
		 * // Create ArrayAdapter using the planet list. listAdapter = new
		 * ArrayAdapter<String>(this, R.layout.today_row, provinceList);
		 * 
		 * // Set the ArrayAdapter as the ListView's adapter.
		 * mainListView.setAdapter(listAdapter);
		 */
		mainListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				// ListView Clicked item index
				int itemPosition = position;

				// ListView Clicked item value
				String itemValue = "aaa";// (String)
											// mainListView.getItemAtPosition(position);

				// Show Alert
				Toast.makeText(
						getApplicationContext(),
						"Position :" + itemPosition + "  ListItem : "
								+ itemValue, Toast.LENGTH_LONG).show();

			}

		});
	}
}
